package com.qls.web.modules.op.service.impl;

import com.qls.core.entity.OpHtlGroup;
import com.qls.web.modules.op.service.HtlGroupService;
import com.qls.web.modules.op.service.SaveGroupHtlService;
import com.qls.web.modules.vo.GroupHotelIdsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author doyoung
 */
@Service
public class SaveGroupHtlServiceImpl implements SaveGroupHtlService {
    @Autowired
    private HtlGroupService htlGroupService;

    @Async
    @Override
    public void execute(GroupHotelIdsVO group) {
        List<Long> hotelIds = group.getHotelIds();
        Integer storeId = group.getStoreId();
        List<Long> hotelIdsEd = htlGroupService.getHotelIdByStoreId(Long.valueOf(storeId));
        List<OpHtlGroup> list = new ArrayList<>();
        for (Long hotelId : hotelIds) {
            if (hotelIdsEd.contains(hotelId)) {
                continue;
            }
            OpHtlGroup htlGroupEntity = new OpHtlGroup();
            htlGroupEntity.setBlonPlantform(group.getBlonPlantform());
            htlGroupEntity.setDtId(group.getDtId());
            htlGroupEntity.setGroupId(group.getId());
            htlGroupEntity.setHotelId(hotelId);
            htlGroupEntity.setStoreId(group.getStoreId());
            htlGroupEntity.setId(Long.valueOf(hotelId + "" + group.getStoreId()));
            list.add(htlGroupEntity);
        }
        htlGroupService.saveOrUpdateBatch(list, 200);
    }
}
